package com.yl.framework.web.service;

import cn.hutool.core.util.StrUtil;
import com.yl.common.config.jianke.JianKeProperties;
import com.yl.common.utils.SecurityUtils;
import com.yl.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yuyu
 */
@Service
public class JianKeTokenService {



    @Autowired
    private JianKeProperties jianKeProperties;

    /**
     * 解析token 获取userName
     * @param token
     * @return
     */
    public String getUserNameByToken(String token){
        //解密获取用户账号 建科数据解密后 格式如 admin@2024-12-12 00:00:00 账号就是admin
        String userStr = SecurityUtils.decryptAES(token, jianKeProperties.getKey());
        if(StringUtils.isEmpty(userStr)||!userStr.contains("@")){
            return "";
        }

        String[] split = userStr.split("@");
        String userName = split[0];
        if(StringUtils.isEmpty(userName)){
            return "";
        }
        return userName;
    }


}
